﻿#include "dxstdafx.h"
#include "StrategyMapData.h"
#include "Strategy/CStrategyDefine.h"

bool CStrategyMapData::ReadHeightMap()
{
	std::wstring szRcPathOut;
	int nTerrainWidth, nTerrainHeight;

	CommonFunc::RelativePath2FullPath(L"\\ResFile\\Scene\\Strategy\\topology.bmp", szRcPathOut);
	BYTE* pHeightBuf = nullptr;
	if (!CommonFunc::Read8BitBmpWithBYTE(szRcPathOut, pHeightBuf, &nTerrainWidth, &nTerrainHeight) ||
		nTerrainWidth != c_nTerrainWidth || nTerrainHeight != c_nTerrainHeight)
	{
		CommonFunc::ErrorMessageBox(L"Read Topology Map Failure!");
		return false;
	}
	m_pHeightBuf.reset(pHeightBuf);
	return true;
}

bool CStrategyMapData::CreateTerrainData()
{
	int nTerrainWidth, nTerrainHeight;
	std::wstring szRcPathOut;
	CommonFunc::RelativePath2FullPath(L"\\ResFile\\Scene\\Strategy\\terrain.bmp", szRcPathOut);
	BYTE* pTerrainBuf = nullptr;
	if (!CommonFunc::Read8BitBmpWithBYTE(szRcPathOut, pTerrainBuf, &nTerrainWidth, &nTerrainHeight) ||
		c_nTerrainWidth != nTerrainWidth || c_nTerrainHeight != nTerrainHeight)
	{
		CString strError("Read Terrain Map Failure!");
		CommonFunc::ErrorMessageBox(strError);
		return false;
	}
	m_pTerrainBuf.reset(pTerrainBuf);
	return true;
}
